package Game;

import Animation.Grid;
import Animation.Square;
import java.util.HashMap;

public class Board
{
    HashMap<String, Room> rooms;
    Square[][] board;
    Square boardSquare;
    Grid grid;


    public Board()
    {
        //Initialize the board square
        boardSquare = new Square("board", 10, 690, 680); // create a square of type board with 20px padding on x and y
        
        //Initialze the 2d array of spaces
        board = new Square[22][22];

        //Initialize the grid
        grid = new Grid();

        //fill the board with spaces
        loadSpaces();

        //Build the rooms to be used by the game board.
        rooms = new HashMap<String, Room>();
        rooms.put("Kitchen", new Room("Kitchen"));
        rooms.put("Ballroom", new Room("Ballroom"));
        rooms.put("Conservatory", new Room ("Conservatory"));
        rooms.put("Billiard Rooom", new Room("Billiard Room"));
        rooms.put("Library", new Room("Library"));
        rooms.put("Study", new Room("Study"));
        rooms.put("Hall", new Room("Hall"));
        rooms.put("Lounge", new Room("Lounge"));
        rooms.put("Dining Room", new Room("Dining Room"));
    }

    public boolean isAdjacent(Room currentRoom, Room destination)
    {
        boolean adjacent = false;

        if(currentRoom.getRoomName().equals("Kitchen"))
        {
            if((destination.getRoomName().equals("Study")) || (destination.getRoomName().equals("Ballroom"))
                    || (destination.getRoomName().equals("Dining Room")))
            {
                adjacent = true;
            }
        }

        else if (currentRoom.getRoomName().equals("Ballroom"))
        {
            if((destination.getRoomName().equals("Kitchen")) || destination.getRoomName().equals("Conservatory"))
            {
                adjacent = true;
            }
        }

        else if (currentRoom.getRoomName().equals("Conservatory"))
        {
            if((destination.getRoomName().equals("Lounge")) || (destination.getRoomName().equals("Ballroom"))
                    || (destination.getRoomName().equals("Billiard Room")))
            {
                adjacent = true;
            }
        }
        else if (currentRoom.getRoomName().equals("Billiard Room"))
        {
            if((destination.getRoomName().equals("Conservatory")) || destination.getRoomName().equals("Library"))
            {
                adjacent = true;
            }
        }
        else if (currentRoom.getRoomName().equals("Library"))
        {
            if((destination.getRoomName().equals("Billiard Room")) || destination.getRoomName().equals("Study"))
            {
                adjacent = true;
            }
        }
        else if (currentRoom.getRoomName().equals("Study"))
        {
            if((destination.getRoomName().equals("Kitchen")) || (destination.getRoomName().equals("Library"))
                    || (destination.getRoomName().equals("Hall")))
            {
                adjacent = true;
            }
        }
        else if (currentRoom.getRoomName().equals("Hall"))
        {
            if((destination.getRoomName().equals("Study")) || destination.getRoomName().equals("Lounge"))
            {
                adjacent = true;
            }
        }
        else if (currentRoom.getRoomName().equals("Lounge"))
        {
            if((destination.getRoomName().equals("Conservatory")) || (destination.getRoomName().equals("Dining Room"))
                    || (destination.getRoomName().equals("Hall")))
            {
                adjacent = true;
            }
        }
         else if (currentRoom.getRoomName().equals("Dining Room"))
        {
            if((destination.getRoomName().equals("Kitchen")) || destination.getRoomName().equals("Lounge"))
            {
                adjacent = true;
            }
        }

        return adjacent;
    }

    private void loadSpaces()
    {
       // the clue board is a 22x22 grid + spaces for starting points and rooms.
        int spaceCountX = 0;
        int spaceCountY = 0;

        //temporary x and y positions usef within the loop.
        int xPos = 20;
        int yPos = 50;

        int size = 30;
        while(spaceCountX < 22)
        {
            spaceCountY=0;
            yPos = 50;
            while(spaceCountY < 22)
            {
                addSquare(new Square("space", xPos, yPos, size), spaceCountX, spaceCountY);
                yPos+=size;
                spaceCountY++;
            }
            xPos += size;
            spaceCountX++;
        }
    }
    private void addSquare(Square square, int xIndex, int yIndex)
    {
        if((square != null) && ((xIndex < 22) && (yIndex < 22)))
            board[xIndex][yIndex] = square;
    }

    public Square[][] getBoard() {
        return board;
    }

    public Square getBoardSquare() {
        return boardSquare;
    }

    public HashMap<String, Room> getRooms() {
        return rooms;
    }

    public Grid getGrid() {
        return grid;
    }
   
}